package scanner.com.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import scanner.com.adapter.HistoryRecordAdapter;
import scanner.com.entity.ContactEntity;
import scanner.com.entity.RecordEntity;
import scanner.com.scanner.R;

/**
 * Created by longteng on 2016-6-7.
 */
public class HistoryActivity extends BaseActivity{
    private ListView historyListView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        findView();
        initView();
    }

    @Override
    protected void findView() {
        historyListView = (ListView) findViewById(R.id.history_listView);
    }

    @Override
    protected void initView() {
        HistoryRecordAdapter historyRecordAdapter = new HistoryRecordAdapter(HistoryActivity.this,getRecordData());
        historyListView.setAdapter(historyRecordAdapter);
        historyListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(HistoryActivity.this, "第"+position+"条记录被点击", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private List<RecordEntity> getRecordData(){
        List<RecordEntity> recordEntityList = new ArrayList<>();
        ContactEntity contactEntity = new ContactEntity("李二狗","1388888888");
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"测试文本", RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.CONTACT,contactEntity, RecordEntity.RECORD_FROM.SCAN));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.URL,"http://www.baidu.com", RecordEntity.RECORD_FROM.MAKE));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.TEXT,"哈哈啊哈", RecordEntity.RECORD_FROM.SCAN));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.CONTACT,contactEntity, RecordEntity.RECORD_FROM.SCAN));
        recordEntityList.add(new RecordEntity(RecordEntity.RECORD_TYPE.URL,"http://www.google.com", RecordEntity.RECORD_FROM.MAKE));
        return recordEntityList;
    }
}
